package com.ecnu.web.controller.incubation;

import com.ecnu.common.core.controller.BaseController;
import com.ecnu.common.core.domain.AjaxResult;
import com.ecnu.common.core.domain.model.LoginUser;
import com.ecnu.common.core.page.TableDataInfo;
import com.ecnu.system.domain.Project;
import com.ecnu.system.domain.dto.incubation.FactoryPageDTO;
import com.ecnu.system.domain.dto.incubation.IncubationFactoryDTO;
import com.ecnu.system.service.IIncubationFactoryService;
import com.ecnu.system.service.IIncubationFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "二期_成果认领")
@RequestMapping("/incubation/claim")
@Validated//用来校验controller参数带@notblack类似的注解
public class ClaimController extends BaseController {
    @Autowired
    private IIncubationFactoryService incubationFactoryService;
    @Autowired
    private IIncubationFileService incubationFileService;
    private static LoginUser getProUser() {
        LoginUser loginUser = new LoginUser();
        //看情况是否需要优化--获取登录信息问题
        try {
            loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {

        }
        return loginUser;
    }
    @ApiOperation(value = "任务认领查询")
    @PostMapping("/claimList")
    public TableDataInfo claimList(@RequestBody FactoryPageDTO dto) {
        LoginUser proUser = getProUser();
        return incubationFactoryService.claimList(dto, proUser);
    }
//    @ApiOperation(value = "任务认领查询（前台）")
//    @PostMapping("/list")
//    public TableDataInfo list(@RequestBody FactoryPageDTO dto) {
//        LoginUser proUser = getProUser();
//        return incubationFactoryService.listForClaim(dto, proUser);
//    }
    /**
     * 任务认领接口
     */
    @ApiOperation(value = "任务认领")
    @PostMapping("/edit")
    public AjaxResult claimEdit(@RequestBody IncubationFactoryDTO dto) {
        LoginUser loginUser = getLoginUser();
        return incubationFactoryService.claimEdit(dto, loginUser);
    }
    /**
     * 取消认领接口
     */
    @ApiOperation(value = "取消认领")
    @PostMapping("/del")
    public AjaxResult claimDel(@RequestBody String ids) {
        LoginUser loginUser = getLoginUser();
        return incubationFactoryService.claimDel(ids, loginUser);
    }
    @ApiOperation(value = "取消认领(多选)")
    @PostMapping("/delList")
    public AjaxResult claimDelList(@RequestBody String[] ids) {
        LoginUser loginUser = getLoginUser();
        return incubationFactoryService.claimDelList(ids, loginUser);
    }
}
